#ifndef _LINUX_ALSA_SOUND_HEAD_H
#define _LINUX_ALSA_SOUND_HEAD_H
#include <iostream>
#include <alsa/asoundlib.h>
#include <vector>

using namespace std;

typedef struct
{
	snd_pcm_access_t  access;
	snd_pcm_format_t  format;
	int               channels;
	uint32_t          sampleRate; //采样率
	uint32_t          sampleBits; //样本多少位表示
	snd_pcm_uframes_t frames;     //帧数
} pcm_hw_params_t;

class LinuxAlsaSound
{
public:
	LinuxAlsaSound();
	bool open(const string &pcmDevice, snd_pcm_stream_t stream);
	bool setParams(pcm_hw_params_t *parm);
	bool record(uint32_t mtime, vector<uint8_t> &pcmData); // ms
	//把录制的数据存到文件
	bool recordPCMData(uint32_t time, const string &filename);
	bool recordWAVData(uint32_t time, const string &filename);
	void pause(void);
	void resume(void);

private:
	snd_pcm_t *          pcmHandle;
	snd_pcm_hw_params_t *pcmParams;
	uint16_t             channels;
	uint32_t             sampleBits; //采样的位数
};

#endif